package svgedit.gui.actions;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

import svgedit.gui.Circle;
import svgedit.gui.Frame;
import svgedit.gui.Line;
import svgedit.gui.Rect;
import svgedit.gui.View;

public class NewAction extends AbstractAction{

	public static ArrayList<Circle> circles = View.getCircles();
	public static ArrayList<Line> lines = View.getLines();
	public static ArrayList<Rect> rects = View.getRects();
	public static ArrayList<Color> colors = View.getColors();
	private Frame frame;
	JFileChooser dialog = new JFileChooser();
	/** Create this action for the given frame */
	public NewAction(Frame frame) {
		super("New");
		this.frame = frame;
	}

	public void actionPerformed(ActionEvent arg0) 
	{
		if(frame.view.getSaveState() !=0)
		{
	        int exit =JOptionPane.showConfirmDialog(frame,"Do you want to save this file before you create a new one?"
	                        ,"Confrim Exit", JOptionPane.YES_NO_CANCEL_OPTION);
	        if (exit==JOptionPane.YES_OPTION) {
		
	        	new SaveAsUtil().SaveAs(frame);
	        	frame.view.setSaveState(0);
				frame.newFile();
		    	frame.deleteSelected();
	        }
	        if (exit==JOptionPane.NO_OPTION) {
	        	frame.view.setSaveState(0);
				frame.newFile();
		    	frame.deleteSelected();
	        	
	        }
	        if (exit==JOptionPane.CANCEL_OPTION) {
	        	
	        }
	        	
		}
	}
}